<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../../css/reset.css" />
		<link rel="stylesheet" type="text/css" href="login.css" />
		<link rel="stylesheet" type="text/css" href="../../../../common/footer/footer.css" />

		<link rel="stylesheet" type="text/css" href="../../../../common/js/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="../../../../common/js/bootstrap-3.3.7-dist/css/bootstrap-theme.css" />
		<link rel="stylesheet" type="text/css" href="../../../css/store_member/style.css" />

		<title></title>
		<script src="../../../js/jquery-2.2.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../common/js/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>

		<!--cookie 操作插件-->
		<script src="../../../js/jquery.cookie.js"></script>
		<script type="text/javascript">
			var local = 'http://47.104.13.109/member-service';
			var namestatus = false;
			emailstatus = false;
			$(function() {
				//验证密码
				$("#repwd").on("blur", function() {
					var pwd = $("#pwd").val(),
						repwd = $("#repwd").val();
					console.log(pwd + repwd);
					if(repwd != pwd) {

						alert("两次密码不一致!");
						$("#repwd").val("");
					}
				})

				//获取验证码
				$("#getBtn").on("click", function() {
						var phone = $("#phone").val();
						var reg = /^1[0-9]{10}$/;
						console.log(phone);
						if(reg.test(phone)) {
							time(this)
							$.ajax({
								type: "get",
								url: local + '/register/send-sms-code',
								async: false,
								data: {
									'tel': phone,
								},
								success: function(res) {
									console.log(res);
									$("#getBtn").prop("disabled", 'disabled');
									$("#getBtn").text("请稍等");
									$("#getBtn").css("background", "gray");
								},
								error: function(error) {
									console.log(error);
									var s = JSON.parse(error.responseText);
									alert(s.error_message);
								}
							});
						} else {
							alert("请输入有效的手机号码!");
						}
					})
					//60s重置验证码
				var wait = 59;

				function time(o) {
					if(wait == 0) {
						o.removeAttribute("disabled");
						o.innerHTML = "免费获取";
						$("#getBtn").css("background", "red");
						wait = 59;
					} else {

						o.setAttribute("disabled", true);

						o.innerHTML = "重新发送(" + wait + ")";
						wait--;
						setTimeout(function() {
							time(o)
						}, 1000)
					}
				}
				//验证验证码 注册
				$(".add_btn").on("click", function() {
					var pwd = $("#pwd").val(),
						repwd = $("#repwd").val(),
						phone = $("#phone").val(),
						ganen = $("#ganhao").val(),
						dongtai = $("#dongTai").val();
					var datas = {
						'license': 1,
						'password': repwd,
						'thankNum': ganen,
						'tel': phone,
						'smsCode': dongtai
					};
					if(ganen == null || ganen == "") {
						datas = {
							'license': 1,
							'password': repwd,
							'tel': phone,
							'smsCode': dongtai
						};
					}

					if(dongtai && phone) {
						//注册
						$.ajax({
							type: "post",
							url: local + '/register/mobile-register',
							async: false,
							data: datas,
							success: function(res) {
								console.log(res);
								$.ajax({
									type: "get",
									url: local + '/auth/static-login',
									async: true,
									data: {
										'tel': phone,
										'password': repwd,
									},
									success: function(res) {
										console.log(res);
										if(res.islogin) {
											$.cookie('tokenReztApp', res.token, {
												expires: 7,
												path: '/'
											});
											$.cookie("tokenRh", res.token, {
												expires: 7,
												path: '/'
											});
											$.cookie('memberId', res.id, {
												expires: 7,
												path: '/'
											});
											$.cookie('roleId', res.roleList[0].id, {
												expires: 7,
												path: '/'
											});
											alert("恭喜您，注册成功！");
											window.location.href = "../../../view/coalition/colalition.html";
										} else {
											alert("账号或密码错误！！！");
										}
									},
									error: function(error) {
										var errors = JSON.parse(error.responseText);
										console.log(errors)
										errors = errors.error_message.replace(":", "");
										alert(errors);
									}
								});
							},
							error: function(error) {
								console.log(error);
								alert(error.responseJSON.error_message);
							}
						});
					} else {
						alert("请补全信息!");
					}
				})

			})
		</script>
		<style type="text/css">
			input {
				border: 0;
				outline: none;
			}
			
			.container-fluid {
				padding: 0;
			}
			
			input,
			button {
				border: 0;
				outline: none;
			}
			
			.vip_msg_add input {
				padding-left: 0.277777rem;
			}
			
			.container-fluid ul {
				padding-top: 0.277777rem;
				margin-bottom: 2.777777rem;
			}
			
			.container-fluid ul li {
				padding-left: 0.416666rem;
				padding-right: 0.416666rem;
			}
			
			.header {
				box-shadow: 0.069444rem 0.069444rem 0.069444rem #b3b3b3;
			}
		</style>
	</head>

	<body>
		<div class="header">
			<a href="javascript:history.go(-1)" class="glyphicon glyphicon-menu-left f28 col-xs-4" style="text-align: left;"></a>
			<span class="f28 col-xs-4" style="text-align: center;">注册</span>
			<!--<span class="f28 col-xs-4" style="text-align: right;">会员认证</span>-->
		</div>
		<div class="wrapper">
			<div id="logo" style="padding-top: 1rem;padding-bottom: 1rem;"><img src="../../../images/login/logo.png" />
			</div>
			<div class="section sectionF" style="border: 1px solid #c7c7c7;border-radius: 0.37rem;margin-bottom: 0.4rem;">
				<div></div>
				<div>
					<img src="../../../images/login/ico_sign_02.png" />
					<input type="text" id="phone" placeholder="请输入手机号" style="height: 0.9rem;" />
				</div>
				<div></div>
			</div>

			<div class="section sectionF" style="border: 1px solid #c7c7c7;border-radius: 0.37rem;margin-bottom: 0.4rem;">
				<div></div>
				<div>
					<img src="../../../images/login/ico_sign_02.png" />
					<input style="height: 0.9rem" type="text" id="dongTai" placeholder="请输入验证码" />
				</div>
				<div></div>
				<div style="position:absolute ; z-index: 100;right: 0.3rem;top: 0.3rem;font-size: 0.388888rem; color:red;"><button style="background: red;color: white;border: 0;border-radius:1rem ;float: right;margin-right: .2rem;" id="getBtn">免费获取</button></div>
			</div>

			<div class="section sectionF" style="border: 1px solid #c7c7c7;border-radius: 0.37rem;margin-bottom: 0.4rem;">
				<div></div>
				<div>
					<img src="../../../images/login/ico_sign_02.png" />
					<input type="password" id="pwd" placeholder="密码" style="height: 0.9rem;" />
				</div>
				<div></div>
			</div>
			<div class="section sectionF" style="border: 1px solid #c7c7c7; margin-bottom: 0.1rem;border-radius: 0.37rem;">
				<div></div>
				<div>
					<img src="../../../images/login/ico_sign_02.png" />
					<input type="password" id="repwd" placeholder="请输入密码" style="height: 0.9rem;" />
				</div>
				<div></div>

			</div>
			<div style="margin-bottom: 0.5em;font-size: 0.388888rem; margin-left: 12%; color:#c7c7c7;">*(6-20)位英文字母加数字</div>

			<div class="section sectionF" style="border: 1px solid #c7c7c7;border-radius: 0.37rem;margin-bottom: 0.4rem;">
				<div></div>
				<div>
					<img src="../../../images/login/ico_sign_01.png" />
					<input type="password" id="ganhao" placeholder="请输入感恩号" style="height: 0.9rem;" />
				</div>
				<div></div>
			</div>
			<div class="section">
				<a href="#" id="login">
					<div></div>
					<div id="loginBtn">
						<button class="add_btn">注册</button>
						<!--<p><span>注</span><span>册</span></p>-->
					</div>
					<div></div>
				</a>
			</div>

		</div>
	</body>

</html>